package com.yanqu.road.dao.impl.activity.jianchuanghua;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.jianchuanghua.ChuangHuaInfo;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * 窗花配置
 */
public class ChuangHuaInfoDaoImpl extends TempDao {

    private static final String getChuangHuaInfoListSql = "select * from t_s_activity_chuanghua_weight where activityId = ? order by id asc";

    public List<ChuangHuaInfo> getChuangHuaInfoList(int activityId) {
        List<ChuangHuaInfo> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getChuangHuaInfoListSql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                ChuangHuaInfo chuangHuaInfo = new ChuangHuaInfo();
                chuangHuaInfo.setActivityId(rs.getInt("activityId"));
                chuangHuaInfo.setId(rs.getInt("id"));
                chuangHuaInfo.setName(rs.getString("name"));
                chuangHuaInfo.setDesc(rs.getString("desc"));
                chuangHuaInfo.setQuality(rs.getInt("quality"));
                chuangHuaInfo.setWeight(rs.getInt("weight"));
                chuangHuaInfo.setIntegral(rs.getInt("integral"));
                chuangHuaInfo.setSort(rs.getInt("sort"));
                list.add(chuangHuaInfo);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

}
